<?php
namespace ImiDemo\HttpDemo\MainServer\Controller;

use Imi\Controller\HttpController;
use Imi\Server\View\Annotation\View;
use Imi\Server\Route\Annotation\Route;
use Imi\Server\Route\Annotation\Action;
use Imi\Server\Route\Annotation\Controller;
use Imi\Server\Session\Session;

/**
 * Session 演示
 * @Controller("/Session/")
 * @View(renderType="json")
 */
class SessionController extends HttpController
{
    /**
     * Session 写入
     * 访问：http://127.0.0.1:8080/Session/set
     * 
     * @Action
     * @return void
     */
    public function set()
    {
        $hash = uniqid('', true);
        Session::set('hash', $hash);
        return [
            'action'=>    'set',
            'hash'    =>    $hash,
        ];
    }

    /**
     * Session 读取
     * 访问：http://127.0.0.1:8080/Session/get
     * 
     * @Action
     * @return void
     */
    public function get()
    {
        return [
            'action'=>    'get',
            'hash'    =>    Session::get('hash'),
        ];
    }

}